package com.wn.inventory.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.ActivitiStartEntity;
import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Hr;
import com.wn.entity.InspectionInWarehouseApplication;
import com.wn.inventory.feign.ActivitiFeignClient;
import com.wn.inventory.mapper.InspectionInWarehouseApplicationMapper;
import com.wn.inventory.service.InspectionInWarehouseApplicationService;
import com.wn.inventory.vo.InspectionInWarehouseApplicationVo;
import com.wn.utils.CurrentTime;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ author     ：NST
 * @ date       ：Created in 2022/10/21 14:21
 * @ description：
 * @ modified By：
 * @ version:
 */
@Service
public class InspectionInWarehouseApplicationImpl implements InspectionInWarehouseApplicationService {
    @Autowired
    InspectionInWarehouseApplicationMapper inspectionInWarehouseApplicationMapper;
    @Autowired
    ActivitiFeignClient activitiFeignClient;
    @Override
    public void insert(InspectionInWarehouseApplication inspectionInWarehouseApplication, HttpServletRequest request) {
        inspectionInWarehouseApplication.setApplicant(new Hr(Integer.parseInt(request.getHeader("userId"))));
        inspectionInWarehouseApplication.setInWarehouseTime(CurrentTime.getCurrentTime());
        String identifier="IIWA"+CurrentTime.getCurrentTimeString();
        inspectionInWarehouseApplication.setIdentifier(identifier);
        ResponseEntity<String> entity = activitiFeignClient.startInstance(new ActivitiStartEntity("in_warehouss_application_id", "user1", request.getHeader("userWorkNumber")));
//        activitiFeignClient.completeTask(new ActivitiCompleteEntity("in_warehouss_application_id",entity.getData(),"user1",));
        inspectionInWarehouseApplication.setActivitiInstanceId(entity.getData());
        inspectionInWarehouseApplicationMapper.insert(inspectionInWarehouseApplication);
    }

    /**
     * @ param  inspectionInWarehouseApplicationVo
     * @return com.wn.common.PageBean<com.wn.entity.InspectionInWarehouseApplication>
     * @ author nst
     * @ date 2022/10/21 14:23
     * @ Description 多条件查询来料检验入库申请表信息
     */
    @Override
    public PageBean<InspectionInWarehouseApplication> getByCondition(InspectionInWarehouseApplicationVo inspectionInWarehouseApplicationVo) {
        Page<InspectionInWarehouseApplication> page = PageHelper.startPage(inspectionInWarehouseApplicationVo.getCurrPage(), inspectionInWarehouseApplicationVo.getPageSize());
        List<InspectionInWarehouseApplication> list = inspectionInWarehouseApplicationMapper.getByCondition(inspectionInWarehouseApplicationVo.getInspectionInWarehouseApplication());
        return PageBeanUtil.getPageBean(list, page, inspectionInWarehouseApplicationVo.getCurrPage(), inspectionInWarehouseApplicationVo.getPageSize());
    }
}
